package com.dodayum.controller;

import com.dodayum.Info;
import com.google.common.base.Throwables;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping
public class Controller {

    @Resource
    RocketMQTemplate rocketMQTemplate;

    @GetMapping("send")
    public String sendMsg() {
        rocketMQTemplate.asyncSend("springboot-topic", "hello rocketMQ", new SendCallback() {
                    @Override
                    public void onSuccess(SendResult sendResult) {
                        System.out.println("成功了");
                    }

                    @Override
                    public void onException(Throwable throwable) {
                        System.out.println("失败了");
                        System.out.println(Throwables.getStackTraceAsString(throwable));
                    }
                }, 1000);
//        rocketMQTemplate.convertAndSend("springboot-topic", "hello rocketMQ");
        return "OK";
    }

}
